package com.baosight.sczx.zm.ce.service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.baosight.iplat4j.core.ei.EiBlock;
import com.baosight.iplat4j.core.ei.EiColumn;
import com.baosight.iplat4j.core.ei.EiConstant;
import com.baosight.iplat4j.core.ei.EiInfo;
import com.baosight.iplat4j.ep.ServiceEPBase;
import com.baosight.sczx.common.zm.basetools.StaticTools;
import com.baosight.sczx.common.zm.cInterface.Department;
import com.baosight.sczx.common.zm.cInterface.ce.Equipment;
import com.baosight.sczx.common.zm.cInterface.cs.Engineering;
import com.baosight.sczx.zm.ce.domain.ZMCEEquipmentDynamic;

/**
 * <p>Title: ServiceZMCE32.java</p>
 * <p>Description: </p>
 * <p>Copyright: Baosight Software LTD.co Copyright (c) 2002</p>
 * <p>Company: Baosight Software</p>
 * @author  高强
 * @version 1.0
 * <pre>Histroy:
 *          2011-12-15 下午02:40:20  高强  Create
 *</pre>
 */
public class ServiceZMCE32 extends ServiceEPBase {
	
	/**
	 * 初始化方法
	 * <p>Function: initLoad</p>
	 * <p>Description: </p>
	 * <p>return value: ServiceZMCE32</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2011-12-16下午04:26:16 高强
	 * </p>
	 *
	 */
	public EiInfo initLoad(EiInfo inInfo) {
		EiInfo outInfo = null;
		inInfo.addBlock(EiConstant.resultBlock).set("showCount", "true");//如果不加这个，翻页的统计和显示是错误的
		outInfo = query(inInfo);
		outInfo.addBlock(getMoveType());//变动类型
		outInfo.addBlock(Department.getInstance().getConstructionUnit("cmes.ce.department", "orgCode", "orgName", false));
		outInfo.addBlock(getEngineering());
		outInfo.addBlock(Equipment.getEquipmentBlock("cmes.ce.equipment", null));
		return outInfo;
	}

	/**
	 * 设备变动查询
	 * <p>Function: query</p>
	 * <p>Description: </p>
	 * <p>return value: ServiceZMCE32</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *   2011-12-16下午04:26:16 高强
	 * </p>
	 *
	 */
	@Override
	public EiInfo query(EiInfo inInfo) {
		StaticTools.setQueryParameters(inInfo, "fdStatus", "生效", true);//添加查询条件 操作用户
		EiInfo outInfo = super.query(inInfo, "ZMCEEquipmentDynamic.query", new ZMCEEquipmentDynamic());				
		return outInfo;
	}

	/**
	 * 获取变动类型的下拉框
	 * <p>Function: getMoveType</p>
	 * <p>Description: </p>
	 * <p>return value:EiBlock</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2011-12-16下午04:26:16 高强
	 * </p>
	 *
	 */
	@SuppressWarnings("rawtypes")
	private EiBlock getMoveType()
	{
		EiBlock block = new EiBlock("cmes.ce.type");
		
		EiColumn eiColumn = new EiColumn("label");
		eiColumn.setType("C");
		block.addMeta(eiColumn);
		
		eiColumn = new EiColumn("value");
		eiColumn.setType("C");
		block.addMeta(eiColumn);
		
		List<Map> list = new ArrayList<Map>();
		
		Map<String, String> _map;
		
		_map = new HashMap<String, String>();
		_map.put("value", "领用");
		_map.put("label", "领用");
		list.add(_map);
		
		_map = new HashMap<String, String>();
		_map.put("value", "启封");
		_map.put("label", "启封");
		list.add(_map);
		
		_map = new HashMap<String, String>();
		_map.put("value", "封存");
		_map.put("label", "封存");
		list.add(_map);
		
		_map = new HashMap<String, String>();
		_map.put("value", "移交");
		_map.put("label", "移交");
		list.add(_map);
		
		_map = new HashMap<String, String>();
		_map.put("value", "闲置");
		_map.put("label", "闲置");
		list.add(_map);
		
		_map = new HashMap<String, String>();
		_map.put("value", "报废");
		_map.put("label", "报废");
		list.add(_map);	
		
		block.setRows(list);
		return block;
	}
	
	/**
	 * 获得工程
	 * <p>Function: getEngineering</p>
	 * <p>Description: </p>
	 * <p>return value:EiBlock</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2011-12-16下午04:26:16 高强
	 * </p>
	 *
	 */
	@SuppressWarnings("rawtypes")
	private EiBlock getEngineering()
	{
		EiBlock block = new EiBlock("cmes.ce.engineering");
		
		EiColumn eiColumn = new EiColumn("fdKeyId");
		eiColumn.setType("C");
		block.addMeta(eiColumn);
		
		eiColumn = new EiColumn("fdName");
		eiColumn.setType("C");
		block.addMeta(eiColumn);
		
		List<Map> list = Engineering.getEngineerings(null);
		
		block.setRows(list);
		return block;
	}
}
